package com.example.yuejian.yuejian.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.yuejian.yuejian.R;
import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.Register;
import com.example.yuejian.yuejian.model.UserModel;

public class RegisterActivity extends AppCompatActivity {
       private EditText et_phone;
       private  EditText et_password;
       private EditText et_confirm_password;
       private EditText et_username;
       private Button btn_confirm_register;
    private ModleListener<Register> modleListener=new ModleListener<Register>() {
        @Override
        public void onResponse(Register o) {
            Register res=o;
            String result=res.getRetMsg();
            int code=res.getRetCode();
            if(0==code)
            {
                //失败处理
                Toast.makeText(RegisterActivity.this, result, Toast.LENGTH_SHORT).show();
            } else
            {

                //登录成功处理
                Toast.makeText(RegisterActivity.this, result, Toast.LENGTH_SHORT).show();
                String str_user=et_phone.getText().toString();
                Intent intent=new Intent();
                intent.putExtra("username",str_user);
                setResult(RESULT_OK,intent);
                finish();
            }

        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(RegisterActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initViews();
    }
    private  void initViews()
    {
        et_phone=(EditText)findViewById(R.id.et_register_telephone);
        et_password=(EditText)findViewById(R.id.et_register_password);
        et_confirm_password=(EditText)findViewById(R.id.et_register_confirm_password);
        et_username=(EditText)findViewById(R.id.et_register_username);
        btn_confirm_register=(Button)findViewById(R.id.btn_register_confirm_ok);
    }
    public void Register_ok(View view)
    {
        //1
        UserModel userModel=new UserModel();
        userModel.Register(et_password.getText().toString(),
                et_confirm_password.getText().toString(),
                et_phone.getText().toString(),
                et_username.getText().toString(),modleListener);
    }
}
